package com.itheima;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class test01 {

    @Test
    public void upload() throws IOException {
        XSSFWorkbook Workbook = null;
        try {
            //获得当前测试文档的类
            Workbook = new XSSFWorkbook("E://test01.xlsx");
            //获得第一个表(索引从0开始)
            XSSFSheet sheet = Workbook.getSheetAt(0);
            //最后一行的索引(行时闭区间)
            int lastRowNum = sheet.getLastRowNum();
            for(int i = 0 ; i <= lastRowNum ; i++){

                //获得当前行
                XSSFRow row = sheet.getRow(i);
                //获取当前行的最后一个索引
                short lastCellNum = row.getLastCellNum();
                //循环
                for(int j = 0 ; j < lastCellNum ; j++){

                    //获取当前列的数据
                    XSSFCell cell = row.getCell(j);
                    //打印
                    System.out.println(cell.getStringCellValue());

                }
            }
        } finally {

            if(Workbook!= null){

                Workbook.close();

            }

        }


    }

}
